#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
long long n,m,a[N],o;
int main()
{
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		m+=a[i];
	}
	for(int i=1;i<n;++i)
		if(a[i-1]==a[i]&&a[i-1]==0)
			o=1;
	if(m<n||o)
		cout<<0;
	else
		cout<<1;
	return 0;
}
